#!/usr/bin/env python
# 
# Copyright 2013 <+YOU OR YOUR COMPANY+>.
# 
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# 
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
import blocks_swig as blocks
from random import random 

class qa_protocol_source (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        N = 4
        key_len = 10
        key = [ int(N*random()) for i in range(key_len)]

        snr_seq_len = 20
        snr_seq = [ int(N*random()) for i in range(snr_seq_len)]

        data = [10,9,8,7,6,5,4,3,2,1,0,1, 2, 3,4]

        print "#########################################"
        print "key:", key
        print "SNR sequency:", snr_seq
        print "Data:", data
        print "#########################################"

        pt_src = blocks.protocol_source(key, snr_seq)
        pt_snk = blocks.protocol_sink(key, snr_seq_len)
        
        med = gr.throttle( gr.sizeof_char, 10)
        delay = gr.delay( gr.sizeof_char, 10)

        dt_src = gr.vector_source_b(data, False,1)
        dt_snk = gr.vector_sink_b()

        self.tb.connect(dt_src, pt_src, delay, pt_snk, dt_snk)
        self.tb.run ()

        print dt_snk.data()


if __name__ == '__main__':
    gr_unittest.run(qa_protocol_source, "qa_protocol_source.xml")
